<script type="text/javascript">
function validateEmailForm(){
	
	if(jQuery("#fullname").val()==""){
		alert('Please Provide Your Full Name');
		jQuery("#fullname").focus();
		return false;
	}
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(jQuery("#email").val()) == false){
		alert('Please Provide Your Valid Email Address');
		jQuery("#email").focus();
		return false;
	}

	if(jQuery("#message").val()==""){
		alert('Please Provide Your Message');
		jQuery("#message").focus();
		return false;
	}
	
	return true;	
}
</script>
<?php 
$emailAddress = get_post_meta($post->ID, "emailAddress", true);

$send_email = dirname(__FILE__).'/sendemail.php';
include($send_email)
?>

<div class="archive">
<?php 
if ( have_posts() ) : ?>
<?php  while ( have_posts() ) : the_post();?>

<div class="hentry-meta"><h1> 
<?php if ( has_post_thumbnail() ) the_post_thumbnail('company-logo'); ?> <?php the_title(); ?></h1></div>
<section class="general-wrapper product">

<?php
	$emailAddress=get_post_meta($post->ID, "emailAddress", true);
	$phoneNumber=get_post_meta($post->ID, "phoneNumber", true);
	$contactPerson=get_post_meta($post->ID, "contactPerson", true);
	$siteURL=get_post_meta($post->ID, "siteURL", true);
	$youTubeVideo=get_post_meta($post->ID, "youTubeVideo", true);
	$address=get_post_meta($post->ID, "address", true);
	
	if($siteURL == "")
	{
		$siteURL = 'N/A';
	}elseif(!isValidURL($siteURL))
	{
		$siteURL = '<a style="text-decoration:underline" target="_new" href="http://'.$siteURL.'">'.$siteURL.'</a>';
	}
	else
	{
		$siteURL = '<a style="text-decoration:underline" target="_new" href="'.$siteURL.'">'.$siteURL.'</a>';
	}
?>
<?php if(isset($cmd)): ?>
<div><strong><?php echo $cmd ?></strong></div>
<?php endif; ?>

<div id="tabs">
	<ul>
		<!--<li><a href="#tabs-1">Introduction</a></li>-->
		<li><a href="#tabs-1"><strong>Contact Info</strong></a></li>
        <li><a href="#tabs-2"><strong>Contact Supplier</strong></a></li>
	</ul>
	<!--<div id="tabs-1">
		<?php the_content()?>
	</div>-->
	<div id="tabs-1">
		<p>
        <p><strong style="font-size:16px;">Address</strong>: <?php echo ($address!=""?$address:"N/A"); ?></p>
		<p><strong style="font-size:16px">Tel</strong>: <?php echo ($phoneNumber!=""?$phoneNumber:"N/A"); ?></p>
		<p><strong style="font-size:16px">Email</strong>: <?php echo ($emailAddress!=""?$emailAddress:"N/A"); ?></p>
		<p><strong style="font-size:16px">Website</strong>: <?php echo $siteURL?></p>
</p>
	</div>
    
    <div id="tabs-2">
    <?php if($emailAddress!=""): ?>
    <form action="http://stoneselector.com/cavendish-stone-ltd-2/" method="post" onsubmit="return validateEmailForm()">
    <input type="hidden" name="toAddress" value="<?php echo $emailAddress ?>" />
    <p>
        <p>Your Name<br /><input type="text" name="fullname" id="fullname" class="field-text" /></p>
        <p>Your Email<br /><input type="text" name="email" id="email"  class="field-text" /></p>
        
        <p>Message<br /><textarea name="message" cols="40" rows="7" id="message"  class="field-text"></textarea></p>
        <p><input type="submit" class="field-button" value="Submit" name="emailSender" /></p>
    </p>
    </form>
    <?php else: ?>
    <p><!--<strong>Apologies! This compnay has not an email address.</strong>--></p>
    <?php endif; ?>
    </div>
</div>
<?php 
endwhile;
endif;


function isValidURL($url)
{
	return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}
?>

</div>
